//
//  JZHMycodeViewController.m
//  极致荟
//
//  Created by hetao on 14-5-14.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "JZHMycodeViewController.h"
#import "JZHShare.h"
#import "QRCodeGenerator.h"
@interface JZHMycodeViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *headimge;
@property (weak, nonatomic) IBOutlet UIImageView *vipicon;

@end

@implementation JZHMycodeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self loadMainView];
}

///初始化界面
- (void)loadMainView
{
    [self.headimge.layer setCornerRadius:6.0];
    [self.headimge.layer setBorderWidth:2];
    [self.headimge.layer setBorderColor:[[UIColor whiteColor] CGColor]];
    [self.headimge.layer setMasksToBounds:YES];
    self.navigationItem.title=@"我的二维码";
    UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 12, 20)];
    [leftButton addTarget:self action:@selector(leftDrawerButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    [leftButton setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftBarButton;
    
    
    
    UIButton *rightButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 25, 5)];
    [rightButton addTarget:self action:@selector(rightDrawerButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    
    [rightButton setImage:[UIImage imageNamed:@"详细资料圈圈"] forState:UIControlStateNormal];
    UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    self.navigationItem.rightBarButtonItem = rightBarButton;
    [self addViewData];
    [self vipiconimage];

}

//会员图标显示设置
- (void)vipiconimage
{
    int vip=[User defuceUser].vip;
    if(vip==0)
    {
        if([User defuceUser].sex==1)
        {
            self.vipicon.image=[UIImage imageNamed:@"no1-1"];
        }else
        {
            self.vipicon.image=[UIImage imageNamed:@"no0-1"];
        }
        
        return;
    }
    
    if(vip==1)
    {
        self.vipicon.image=[UIImage imageNamed:@"vip1-1"];
    }else
    {
        self.vipicon.image=[UIImage imageNamed:@"vip2-1"];
    }
}

- (void)addViewData
{
    self.myName.text=[User defuceUser].name;
    
    [ImageCache imageUrl:[User defuceUser].userHeadImage UiImageview:self.headimge];
    
    self.ewm.image=[QRCodeGenerator qrImageForString:[NSString stringWithFormat:@"userId:%d",[User defuceUser].userId] imageSize:self.ewm.frame.size.width];
    
    NSString *str=[[User defuceUser].locationdic objectForKey:@"cityName"];
    str=  [str stringByAppendingFormat:@" %@",[[User defuceUser].locationdic objectForKey:@"quName"]];
    self.myadd.text=str;
    
}
- (void)rightDrawerButtonPress:(UIButton *)but
{
    JZHShare *share=[[NSBundle mainBundle]loadNibNamed:@"JZHShare" owner:self options:nil][0];
    [share show:1 viewcontroller:self];
}
- (void)leftDrawerButtonPress:(UIButton *)but
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
